package cn.zbzcode.hrm.web.controller;

import cn.zbzcode.hrm.doc.CourseDoc;
import cn.zbzcode.hrm.query.CourseQuery;
import cn.zbzcode.hrm.repository.CourseElasticsearchRepository;
import cn.zbzcode.hrm.server.ESService;
import cn.zbzcode.hrm.utils.AjaxResult;
import cn.zbzcode.hrm.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ESController {

    @Autowired
    private CourseElasticsearchRepository courseElasticsearchRepository ;

    @Autowired
    private ESService esService;

    //保存
    @RequestMapping(value = "/es/onLineCourse",method = RequestMethod.POST)
    public AjaxResult onLineCourse(@RequestBody CourseDoc courseDoc){
        courseElasticsearchRepository.save(courseDoc);
        return AjaxResult.me();
    }

    //删除
    @RequestMapping(value="/offLineCourse/{id}",method= RequestMethod.POST)
    public AjaxResult offLineCourse(@PathVariable("id")Long id){
        courseElasticsearchRepository.deleteById(id);
        return AjaxResult.me();
    }

    //查询课程
    @RequestMapping(value = "/es/searchCourse",method = RequestMethod.POST)
    public PageList<CourseDoc> searchCourse(@RequestBody CourseQuery courseQuery){
        return esService.searchCourse(courseQuery);
    }
}